<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<title>收货地址</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/css/shoujisc.css">
<script type="text/javascript" src="/static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="/static/js/woxiangyao.js"></script>
<script type="text/javascript" src="/static/js/TouchSlide.1.1.js"></script>
<script type="text/javascript" src="/static/js/foot.js"></script>
<script type="text/javascript" src="/static/js/myinit.js"></script>
<script type="text/javascript" src="/static/js/xujianbanner.js"></script>
<script type="text/javascript" src="/static/js/cook_shop_cart.js"></script>
<style type="text/css">
	.mypageback{
		float:left;
	}
	.mybtn_del{
		background-repeat: no-repeat;
		background-position: left center;
		background-size: auto 100%;
		padding-left: 25px;
		display:inline-block;
		margin:10px;
		background-image:url('/static/img/del.png');
		
		
	}
	
	.mybtn_edit{
		background-repeat: no-repeat;
		background-position: left center;
		background-size: auto 100%;
		padding-left: 25px;
		display:inline-block;
		margin:10px;
		background-image:url('/static/img/bianji.png');
		
	}
</style>
</head>

<body>
	
    <div class="sjsc-title1" style="height:45px">
    	<h3 class="sjsc-t1l f-l" style="height:45px;line-height:45px"><a class="mypageback"><span><</span>收货地址</a></h3>
        <div style="clear:both;"></div>
    </div>
    
	
	<div id="list">	
		 
	
	
	
	</div>
    
    <a id="toadddizhi"><button class="drdd-btn" style="height:40px;line-height:40px;font-size:16px">新增收货地址</button></a>
	
	<script type="text/javascript">
		var openid =getUrldata('OPENID');
		$('.mypageback').click(function(){
			window.history.go(-1);
		});
		
		function initlist(){
			var url ='/webserver/api/v1/custadr/?format=json&wx_id='+openid;
			$.getJSON(url,function(rs){
				var objects=rs.objects;
				if(objects!=null&&objects!=undefined&&objects.length>0){
					$.each(objects,function(index,item){
						$('#list').append('<dl class="drdd-info7" style="height:auto; style="font-size:14px"" id="'+item.id+'"><dt><p><span class="f-r"  style="font-size:14px">'+item.phoneno+'</span><span class="f-l" style="font-size:14px">'+item.custname+'</span><div style="clear:both;"></div></p><p style="font-size:14px">'+item.cityname+item.detailAdrinfo+'</p></dt><dd style="font-size:14px"><a href="#">></a></dd><div style="clear:both;text-align:right"><div class="mybtn_del" style="color:#FF4D4D">删除</div><div class="mybtn_edit" style="color:#3E9EFF" >编辑</div></div></dl>');
						
					
					});
					$('.drdd-info7').each(function(index,item){
						var id=$(this).attr('id');
						$(this).find('.mybtn_del').click(function(){
							var bb=[];
							
							var aa={};
							aa.NAME="确认";
							aa.ACTION=function(){
								delAAddr(id);
							};
							
							bb.push(aa);
							aa={};
							aa.NAME="取消";
							aa.ACTION=function(){
								
							};
							bb.push(aa);
							toastwithactions("确认删除?",bb);
						
						});
						$(this).find('.mybtn_edit').click(function(){
							document.location.href="xinzengshouhuo.html?OPENID="+openid+"&ID="+id;
						
						});
					});
					
				}
				
			});
			
		
		}
		
		$(document).ready(function(){
			initlist();
		});
		
		$('#toadddizhi').click(function(){
			document.location.href="xinzengshouhuo.html?OPENID="+openid;
		});
		
		function delAAddr(id){
			var url = "/shop/api/deladdress/?id="+id;
		 
			$.post(url,{"id":id},function(rs){
				console.log(rs);
				if(rs){
					$('#'+id).remove();
				}
			},'json');
			 
			
		}
		
		 
	
	</script>
    
</body>
</html>
